home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / doors_1 / doorskl3.zip / XBBSMSG.ZIP / IDXMSG.C < prev    next >
C/C++ Source or Header  |  1991-12-26  |  1KB  |  51 lines

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include "xmsg.h"
  4.  
  5. #define STARTPTRS       512
  6. #define INCPTRS         128
  7.  
  8. #define IDX_ERRNOERR    0
  9. #define IDX_ERRNOMEM    1
  10. #define IDX_ERRNOTEXT   2
  11.  
  12. #ifdef __TURBOC__
  13.     #define _fastcall pascal
  14. #endif
  15.  
  16.  
  17. int _fastcall index_msg (IMSG *m,int width) { \* index the lines of a msg body */
  18.  
  19.     char *t = m->text,*p,*r,line[133];
  20.     word pt = 0,nh = 0;
  21.  
  22.  
  23.     if(!t || !*t) {
  24.         return IDX_ERRNOTEXT;
  25.     }
  26.  
  27.     p = malloc(STARTPTRS * sizeof(char *));
  28.     if(!p) return IDX_ERRNOMEM;
  29.     nh = STARTPTRS;
  30.  
  31.     while(*t) {
  32.         p[pt] = write_line(line,&t,width,(int)m->ctla);
  33.         if(pt + 1 >= nh && *t) {
  34.             r = realloc(p,(nh + INCPTRS) * sizeof(char *));
  35.             if(!r) {
  36.                 break;
  37.             }
  38.             p = r;
  39.             nh += INCPTRS;
  40.             continue;
  41.         }
  42.         if(*t) pt++;
  43.     }
  44.  
  45.     m->numptrs = pt;
  46.     r = realloc(p,pt + 1);
  47.     if(r) p = r;
  48.     m->ptrs = p;
  49.     return IDX_ERRNOERR;
  50. }
  51.